package cn.laixueit;

import java.awt.*;
import java.util.Scanner;

/**
 * 游戏功能
 */
public class Game {

    private  Player player;
    public Game(Player player){
        this.player = player;
    }

    /**
     * 随机生成字符串
     */
    public String getRanStr(){
        StringBuffer sb = new StringBuffer();
        int strLeng = LevelParams.LEVELS[player.levelNo-1].strLeng;
        for (int i = 0; i < strLeng; i++) {
            sb.append((char)(Math.random()*26+97));
        }
        return  sb.toString();
    }

    /**
     * 比较用户录入和系统生成的是否一样
     */
    public void isFlag(String in ,String ranStr){

        if(in.equals(ranStr)){
            // 超时
            player.elapsedTime =  System.currentTimeMillis();
            if((player.elapsedTime-player.startTime)/1000>LevelParams.LEVELS[player.levelNo-1].levelTime){
                System.out.println("超时了,游戏结束");
                System.exit(0);
            }else{
                player.currScore=player.currScore+LevelParams.LEVELS[player.levelNo-1].porce;
                System.out.printf("您当前级别为%d,您的总分为:%d\n",player.levelNo,player.currScore);
            }
        }else{
            System.out.println("输入错误，游戏结束");
            System.exit(0);
        }

    }


  /*  public static void main(String[] args) {
        Game game = new Game();
        while(true) {
            String ranStr = game.getRanStr();
            System.out.println("请输入:" + ranStr);
            Scanner scanner = new Scanner(System.in);
            String in = scanner.next();
            boolean flag = game.isFlag(in, ranStr);
        }
    }*/

}
